/**
 * author:Administrator
 * date:2016/1/6
 * desc:TODO
 */

'use strict';

var Model = require('../model/user.js');
var Sequelize = require('sequelize');
var sequelize = require('../conn/sequelize.js');

var dao = {};
module.exports = dao;

/**
 * create
 */
dao.create = function*(name) {
  var account = yield Model.create({name: name});
  return account;
};


/**
 * query
 */
dao.findById = function *(id) {
  return yield Model.findOne({where: {id: id}});
};

var rawQuery = require('./mysql_comm.js').rawQuery;
dao.findById_withbook = function *(id) {
  var sql =
    ' select user.id as uid, user.name, book.id as bookid, book.name as bookname '
    + ' from user,book '
    + ' where user.id=:id'
    + ' and book.uid=user.id ';
  var opt = {
    replacements: {id: id}
  };
  console.log(sql);
  return yield rawQuery(sql, opt);
};